package com.loadmore.oneday.fragment

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.loadmore.common.base.BaseFragment
import com.loadmore.common.constants.Configs
import com.loadmore.common.router.RouterPath
import com.loadmore.common.util.SPFUtil
import com.loadmore.common.variables.Variables
import com.loadmore.oneday.MainActivity
import com.loadmore.oneday.R
import com.loadmore.oneday.constants.Actions
import com.loadmore.stepcount.StepAlarmManager
import com.loadmore.stepcount.StepCountService
import kotlinx.android.synthetic.main.fragment_mine_setting.*

@Route(path = RouterPath.MineSetting)
class MineSettingFragment :BaseFragment() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_mine_setting
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        logout.setOnClickListener {
            SPFUtil(Configs.User).clear()
            Variables.user = null
            Variables.token = ""
            StepAlarmManager.stopAlarm(context!!)

            val stepIntent = Intent(context, StepCountService::class.java)
            context?.stopService(stepIntent)
            val intent = Intent(context, MainActivity::class.java)
            intent.action = Actions.goLogin
            startActivity(intent)
        }
    }

}